﻿using HarmonyLib;
using JSONClass;
using KBEngine;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
using UnityEngine.UI;
using static UnityEngine.UI.Image;

namespace ncs.lingtian
{
    public partial class LingTianMod
    {


        private static List<DFLingYanLevel> DFLingYanLevelDataList = new List<DFLingYanLevel>();
        private static List<DFZhenYanLevel> DFZhenYanLevelDataList = new List<DFZhenYanLevel>();
        private static Dictionary<int, DFLingYanLevel> DFLingYanLevelDataDict = new Dictionary<int, DFLingYanLevel>();
        private static Dictionary<int, DFZhenYanLevel> DFZhenYanLevelDataDict = new Dictionary<int, DFZhenYanLevel>();
         
        /// <summary>
        /// 加载灵田数据后，修改基础灵力
        /// 灵田的生长等于=基础灵力（阵眼等级）+聚灵等级（聚灵等级基础+催生速度（瓶子））
        /// 灵药生长速度相当于灵田的供给灵力/灵植数量*零植灵力
        /// 6品零植是27000
        /// 9个格子就是27000*9*2=243000
        /// 要想3个月一株6品灵植，灵田就需要基础灵力（）+催生灵力（）+
        /// </summary>
        [HarmonyPostfix, HarmonyPatch(typeof(DFLingYanLevel), nameof(DFLingYanLevel.InitDataDict))]
        public static void DFLingYanLevel_InitDataDict_Postfix()
        {
            Info("DFLingYanLevel_InitDataDict_Postfix");

            foreach (var item in DFLingYanLevel.DataList)
            {
                if (DFLingYanLevel.DataList.Count != DFLingYanLevelDataList.Count)
                {
                    var newItem = new DFLingYanLevel { id = item.id, xiuliansudu = item.xiuliansudu, lingtiansudu = item.lingtiansudu, name = item.name };
                    DFLingYanLevelDataList.Add(newItem);
                    DFLingYanLevelDataDict.Add(newItem.id, newItem);
                }
                var baseItem = DFLingYanLevelDataList.FirstOrDefault(x => x.id == item.id);
                if (baseItem == null) continue;
                item.lingtiansudu = baseItem.lingtiansudu * MainMod.lingtiansudu.Value;
                item.xiuliansudu = MainMod.lingyanxiuliansudu.Value * baseItem.xiuliansudu;
                MainMod.Logger.LogInfo($"灵眼：{item.id} {item.name}--灵田速度：{baseItem.lingtiansudu}=>{item.lingtiansudu} 修炼速度：{baseItem.xiuliansudu}=>{item.xiuliansudu}");
            }
        }

        /// <summary>
        /// 加载灵田数据后，修改基础灵力
        /// 灵药生长速度相当于灵田的供给灵力/灵植数量*零植灵力
        /// 6品零植是27000
        /// 9个格子就是27000*9*2=243000
        /// 要想3个月一株6品灵植，灵田就需要基础灵力（）+催生灵力（）+
        /// </summary>
        [HarmonyPostfix, HarmonyPatch(typeof(DFZhenYanLevel), nameof(DFZhenYanLevel.InitDataDict))]
        public static void DFZhenYanLevel_InitDataDict_Postfix()
        {
            Info("DFZhenYanLevel_InitDataDict_Postfix");

            foreach (var item in DFZhenYanLevel.DataList)
            {
                if (DFZhenYanLevel.DataList.Count != DFZhenYanLevelDataList.Count)
                {
                    var newItem = new DFZhenYanLevel { id = item.id, zhenpanlevel = item.zhenpanlevel, wudaolevel = item.wudaolevel, buzhenxiaohao = item.buzhenxiaohao, xiuliansudu = item.xiuliansudu, lingtiansudu = item.lingtiansudu, lingtiancuishengsudu = item.lingtiancuishengsudu, name = item.name };
                    DFZhenYanLevelDataList.Add(newItem);
                    DFZhenYanLevelDataDict.Add(newItem.id, newItem);
                }

                var baseItem = DFZhenYanLevelDataList.FirstOrDefault(x => x.id == item.id);
                item.lingtiancuishengsudu = baseItem.lingtiancuishengsudu * MainMod.pingzicuishengsudu.Value;
                item.lingtiansudu = baseItem.lingtiansudu * MainMod.julingsudu.Value;
                item.xiuliansudu = MainMod.julingzhenxiuliansudu.Value * baseItem.xiuliansudu;
                MainMod.Logger.LogInfo($"阵眼：{item.name}--灵田催生速度：{baseItem.lingtiancuishengsudu}=>{item.lingtiancuishengsudu} 灵田速度：{baseItem.lingtiansudu}=>{item.lingtiansudu} 修炼速度：{baseItem.xiuliansudu}=>{item.xiuliansudu}");
            }

        }

    }
}
